const name = process.env.VUE_APP_TITLE || "PDF批注H5"; // 网页标题
const port = process.env.port || 19001; // 端口
const path = require("path");
const timeStamp = new Date().getTime()
module.exports = {
  lintOnSave: false,
  devServer: {
    open: false,
    port: port,
    proxy: {
      [process.env.VUE_APP_BASE_API]: {
        // target: "http://219.148.59.51:8400",
        target: "http://192.168.31.2:8100",
        // target: "http://localhost:8300",
        changeOrigin: true,
        secure: false,
        pathRewrite: {
          ["^" + process.env.VUE_APP_BASE_API]: "",
        },
      },
    },
  },
  // rem 的配置
  css: {
    loaderOptions: {
      css: {},
      postcss: {
        plugins: [
          require("postcss-px2rem")({
            // 适配 375 屏幕, 设计图750中量出来的尺寸要 / 2
            // 配置成 37.5 是为了兼容 没有适配 rem 布局的第三方 ui 库
            remUnit: 37.5,
          }),
        ],
      },
    },
    extract: {
      filename: `css/[name].${timeStamp}.css`,
      chunkFilename: `css/[name].${timeStamp}.css`,
    },
  },
  chainWebpack: (config) => {
    // 配置网页标题
    config.plugin("html").tap((args) => {
      args[0].title = name;
      return args;
    });
  },
  // 配置@符
  configureWebpack: {
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "src"),
      },
    },
    output: {
      filename: 'js/[name].[hash].js',
      chunkFilename: 'js/[name].[hash].js',
    },
    module: {
      rules: [{
        test: /pdf\.worker\.(min\.)?js$/,
        // use: 'raw-loader'
        use: {
          loader: 'file-loader',
          options: {
            name: 'static/js/[name].[hash:8].js'
          }
        }
      }]
    }
  },
};